<include file="Public/min-header"/>
<div class="wrapper">
    <include file="Public/breadcrumb"/>
    <style>#search-form > .form-group{margin-left: 10px;}
        .max{
            width: 100%;
            height: auto;
        }
    </style>
    <!-- Main content -->
    <section class="content">
        <div class="container-fluid">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="fa fa-list"></i> 退款列表</h3>
                </div>
                <div class="panel-body">
                    <div class="navbar navbar-default">
                        <form style="display: inline-block" action="{:U('Admin/Order/refund_price_list')}" id="search-form2" class="navbar-form form-inline" method="post">
                            <!--<div class="form-group">-->
                            <!--<select name="is_on_sale" id="is_on_sale" class="form-control">-->
                            <!--<option value="">全部</option>-->
                            <!--<option value="1">上架</option>-->
                            <!--<option value="0">下架</option>-->
                            <!--</select>-->
                            <!--</div>-->

                            <div class="form-group">
                                <label class="control-label" for="input-order-id">关键词</label>
                                <div class="input-group">
                                    <input type="text" name="key_word" value="{$keyWord}" placeholder="搜索词" id="input-order-id" class="form-control">
                                </div>
                            </div>
                            <div class="form-group">
                                <select name="grant" class="form-control">
                                    <option value="10">请选择申请状态</option>
                                    <if  condition="$grant eq 0">
                                        <option value="1">处理中</option>
                                        <option value="0" selected>已取消</option>
                                        <option value="3">已完成</option>
                                        <option value="2">待管理员处理</option>
                                    <elseif condition="$grant eq 2" />
                                        <option value="1">处理中</option>
                                        <option value="0">已取消</option>
                                        <option value="3">已完成</option>
                                        <option value="2" selected>待管理员处理</option>
                                    <elseif condition="$grant eq 3" />
                                        <option value="1">处理中</option>
                                        <option value="0">已取消</option>
                                        <option value="3" selected>已完成</option>
                                        <option value="2" >待管理员处理</option>
                                    <elseif condition="$grant eq 1" />
                                        <option value="1" selected>处理中</option>
                                        <option value="0">已取消</option>
                                        <option value="3">已完成</option>
                                        <option value="2">待管理员处理</option>
                                     <else/>

                                        <option value="1" >处理中</option>
                                        <option value="0">已取消</option>
                                        <option value="3">已完成</option>
                                        <option value="2">待管理员处理</option>
                                    </if>

                                </select>
                            </div>
                            <button type="submit" id="button-filter search-order" class="btn btn-primary search_prize" data-toggle='tooltip'data-original-title="筛选"><i class="fa fa-search"></i> 筛选</button>
                        </form>
                    </div>
                    <div id="ajax_return"></div>
                </div>
                <div class="box-body">
                    <div class="row">
                        <div class="col-sm-12">
                            <table id="list-table" class="table table-bordered table-striped dataTable">
                                <thead>
                                <tr role="row">
                                    <th>id</th>
                                    <th>订单编号</th>
                                    <!--<th>店铺id</th>-->
                                    <!--<th>店铺名称</th>-->
                                    <th>用户名称</th>
                                    <th>商品名称</th>
                                    <th>商品数量</th>
                                    <th>退款类型</th>
                                    <th>退款金额(元)</th>
                                    <th>退款原因</th>
                                    <th>处理状态</th>
                                    <th>申请描述</th>

                                    <th>退款的商品图片</th>
                                    <th>申请状态</th>
                                    <th>申请时间</th>
                                    <th>快递名称</th>
                                    <th>快递单号</th>
                                    <th>结算状态</th>
                                    <th align="center">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <foreach name="refund_data" item="vo" key="k" >
                                    <tr role="row">
                                        <td>{$vo[refund_id]}</td>
                                        <td>{$vo[order_sn]}</td>
                                        <!--<td>{$vo[shop_id]}</td>-->
                                        <!--<td>{$vo[shop_name]}</td>-->
                                        <td>{$vo[user_name]}</td>
                                        <td>{$vo[goods_name]}</td>
                                        <td>{$vo[goods_num]}</td>
                                        <td>
                                            <if condition="$vo[refund_type] eq 1">
                                             退款并且退货
                                             <else />
                                                退款
                                            </if>
                                        </td>
                                        <td>{$vo[amount]}</td>

                                        <td>{$vo[reason]}</td>
                                        <td>
                                            <if condition="$vo[shop_state] eq 1">
                                                待审核
                                                <elseif  condition="$vo[shop_state] eq 2"/>
                                                同意
                                                <elseif  condition="$vo[shop_state] eq 3"/>
                                                拒绝
                                                <elseif  condition="$vo[shop_state] eq 4"/>
                                                已退款退货
                                                <elseif  condition="$vo[shop_state] eq 10"/>
                                                买家发货
                                                <else />
                                                用户已取消
                                            </if>
                                        </td>
                                        <td>{$vo[description]}</td>
                                        <td>
                                            <foreach name="vo['img']" item="val" key="key" >
                                                <img src="{$val}" class="min img" width="50px" height="50px" alt="">
                                            </foreach>
                                        </td>
                                        <td>
                                            <if condition="$vo[refund_state] eq 1">
                                                处理中
                                                <elseif  condition="$vo[refund_state] eq 2"/>
                                                待管理员处理
                                                <elseif  condition="$vo[refund_state] eq 3"/>
                                                已完成
                                                <elseif  condition="$vo[refund_state] eq 0"/>
                                                已取消
                                            </if>

                                        </td>

                                        <td>{$vo[add_time]}</td>

                                        <td>{$vo[express_name]}</td>
                                        <td>{$vo[express_code]}</td>
                                        <td>
                                            <if condition="$vo[settlement_status] eq 1">
                                                已结算
                                                <else/>
                                                待结算
                                            </if>
                                        </td>
                                        <td align="center">
                                            <if condition="$vo['refund_state'] eq 1">
                                                <button type="button"  val="{$vo[refund_id]}" refund_sn="{$vo[refund_sn]}" class="btn btn-success agree">同意退款</button>
                                                <button type="button"  val="{$vo[refund_id]}" class="btn btn-warning bohui">不同意</button>
                                                <!-- <button type="button"  val="{$vo[refund_id]}" class="btn btn-danger del">删除</button> -->
                                            </if>

                                            <if condition="$vo['refund_state'] eq 2">
                                                <button type="button"  val="{$vo[refund_id]}" refund_sn="{$vo[refund_sn]}" class="btn btn-success agree">同意退款</button>
                                                <button type="button"  val="{$vo[refund_id]}" class="btn btn-warning bohui">不同意</button>
                                                <!-- <button type="button"  val="{$vo[refund_id]}" class="btn btn-danger del">删除</button> -->
                                            </if>
                                            
                                            <!--<a class="btn btn-primary" href="{:U('Lottery/addPrize',array('prize_id'=>$vo['prize_id']))}" data-toggle='tooltip'data-original-title="修改"><i class="fa fa-pencil"></i></a>-->
                                            <!--<a class="btn btn-danger" data-id="{$vo.prize_id}" data-toggle='tooltip'data-original-title="删除"><i class="fa fa-trash-o"></i></a>-->
                                        </td>
                                    </tr>
                                </foreach>
                                </tbody>
                                <tfoot>

                                </tfoot>
                            </table>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-6 text-left">
                            <button class="btn btn-default btn-sm checkbox-toggle"><i class="fa fa-square-o"></i></button>
                        </div>
                        <div class="col-sm-6 text-right">{$page}</div>
                    </div>
                </div>
            </div>
        </div>
        <!-- /.row -->

        <div class="modal fade" id="createFileMModal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="createFileTitle">驳回原因</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <form>
                            <div class="form-group">
                                <!--<label for="fileName" class="col-form-label">驳回原因</label>-->
                                <textarea name="" id="fileName" cols="60" rows="5" placeholder="请输入驳回原因"></textarea>
                                <input type="hidden" id="hidden">
                                <!--<input type="text" autofocus class="form-control" >-->
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-primary" id="createFileSureBut">确定</button>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->
<script>
    $(function () {
        $(document).on('click',".img",function(){
            $(this).toggleClass('min');
            $(this).toggleClass('max');
        })

        $(document).on('click','.agree',function(){
            var refund_sn=$(this).attr('refund_sn');
            if(confirm('您确定要退款吗?')){
            $.ajax({
                url:"/index.php?m=Admin&c=Order&a=agree_refund",
                type:"post",
                data:{
                    refund_sn:refund_sn
                },
                beforeSend:function()
                {
                    layer.msg("处理中...",{
                        time: 0
                    })
                },
                dataType:"json",
                success: function(msg){
                    layer.msg(msg.info)
                }
            });
        }
    
        })
        
    })

    $(document).on('click','.bohui',function(){
        ShowCreateModal('驳回原因');
        var refund_id=$(this).attr('val');
        $('#hidden').attr('value',refund_id);
    });
    // 修改弹出框的title, 显示弹框
    function ShowCreateModal(title){
        $("#createFileTitle").text(title);
        $('#createFileMModal').modal('show');
    }
    // 关闭弹框， 获取输入值，然后执行逻辑
    $("#createFileSureBut").click(function (){
        $("#createFileMModal").modal("hide");
        var admin_msg = $("#fileName").val();
        var refund_id = $("#hidden").val();
        $.ajax({
            url:"/index.php?m=Admin&c=Order&a=disagree_refund",
            type:"post",
            data:{id:refund_id,admin_msg:admin_msg},
            dataType:"json",
            success: function(msg){
                if(msg.result ==400 || msg.result=='400'){
                    alert('驳回失败');
                }else {
                    alert('驳回成功');
                    window.location.href="";
                }
            }
        });
    });
    //删除退款申请
    $(document).on('click','.del',function(){
        var id=$(this).attr('val');
        if(confirm('您确定要删除吗?')){
            $.ajax({
                url:"/index.php?m=Admin&c=Order&a=refund_del",
                type:"post",
                data:{id:id},
                dataType:"json",
                success: function(msg){
                    if(msg.result ==400 || msg.result=='400'){
                        alert('删除失败');
                    }else {
                        alert('删除成功');
                        window.location.href="";
                    }
                }
            });
        }

        return false;
    });


</script>
</body>
</html>